<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>注册 | 美多商城</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../C02-Users/CORS.html" />
    
    
    <link rel="prev" href="../C02-Users/UserModel.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="2.2"
        data-chapter-title="注册"
        data-filepath="C02-Users/Register.md"
        data-basepath=".."
        data-revision="Thu May 24 2018 15:58:46 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        美多商城
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="C01-Prepare/index.html">
            
                
                    <a href="../C01-Prepare/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        项目准备
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="C01-Prepare/BusinessModel.html">
            
                
                    <a href="../C01-Prepare/BusinessModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        商业模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="C01-Prepare/DevelopmentProcess.html">
            
                
                    <a href="../C01-Prepare/DevelopmentProcess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        开发流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="C01-Prepare/ProductAnalysis.html">
            
                
                    <a href="../C01-Prepare/ProductAnalysis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        需求分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="C01-Prepare/ProjectStructure.html">
            
                
                    <a href="../C01-Prepare/ProjectStructure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        项目架构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="C01-Prepare/StartProject.html">
            
                
                    <a href="../C01-Prepare/StartProject.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        创建工程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="C01-Prepare/Config.html">
            
                
                    <a href="../C01-Prepare/Config.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        配置
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="C02-Users/index.html">
            
                
                    <a href="../C02-Users/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        用户部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="C02-Users/UserModel.html">
            
                
                    <a href="../C02-Users/UserModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        用户模型类
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.2" data-path="C02-Users/Register.html">
            
                
                    <a href="../C02-Users/Register.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        注册
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="C02-Users/CORS.html">
            
                
                    <a href="../C02-Users/CORS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        跨域CORS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="C02-Users/JWT.html">
            
                
                    <a href="../C02-Users/JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        JWT
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="C02-Users/DRF-JWT.html">
            
                
                    <a href="../C02-Users/DRF-JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        Django REST framework JWT
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="C02-Users/Login.html">
            
                
                    <a href="../C02-Users/Login.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        登录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="C02-Users/FindPassword/index.html">
            
                
                    <a href="../C02-Users/FindPassword/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        找回密码
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.7.1" data-path="C02-Users/FindPassword/Step1.html">
            
                
                    <a href="../C02-Users/FindPassword/Step1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.1.</b>
                        
                        第一步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.2" data-path="C02-Users/FindPassword/Step2.html">
            
                
                    <a href="../C02-Users/FindPassword/Step2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.2.</b>
                        
                        第二步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.3" data-path="C02-Users/FindPassword/Step3.html">
            
                
                    <a href="../C02-Users/FindPassword/Step3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.3.</b>
                        
                        第三步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.4" data-path="C02-Users/FindPassword/Step4.html">
            
                
                    <a href="../C02-Users/FindPassword/Step4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.4.</b>
                        
                        第四步
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="C02-Users/QQLogin/index.html">
            
                
                    <a href="../C02-Users/QQLogin/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        QQ登录
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.8.1" data-path="C02-Users/QQLogin/Step1.html">
            
                
                    <a href="../C02-Users/QQLogin/Step1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.1.</b>
                        
                        第一步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8.2" data-path="C02-Users/QQLogin/Step2.html">
            
                
                    <a href="../C02-Users/QQLogin/Step2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.2.</b>
                        
                        第二步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8.3" data-path="C02-Users/QQLogin/Step3.html">
            
                
                    <a href="../C02-Users/QQLogin/Step3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.3.</b>
                        
                        第三步
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="C02-Users/UserInfo.html">
            
                
                    <a href="../C02-Users/UserInfo.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        用户中心个人信息
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="C02-Users/Email/index.html">
            
                
                    <a href="../C02-Users/Email/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.</b>
                        
                        邮件与验证
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.10.1" data-path="C02-Users/Email/DjangoEmail.html">
            
                
                    <a href="../C02-Users/Email/DjangoEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.1.</b>
                        
                        Django发送邮件的方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10.2" data-path="C02-Users/Email/SendEmail.html">
            
                
                    <a href="../C02-Users/Email/SendEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.2.</b>
                        
                        保存邮箱并发送验证邮件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10.3" data-path="C02-Users/Email/VerifyEmail.html">
            
                
                    <a href="../C02-Users/Email/VerifyEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.3.</b>
                        
                        验证邮箱链接
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="C02-Users/Address/index.html">
            
                
                    <a href="../C02-Users/Address/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.</b>
                        
                        收货地址
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.11.1" data-path="C02-Users/Address/AreaSelect.html">
            
                
                    <a href="../C02-Users/Address/AreaSelect.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.1.</b>
                        
                        省市区地址查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11.2" data-path="C02-Users/Address/Cache.html">
            
                
                    <a href="../C02-Users/Address/Cache.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.2.</b>
                        
                        使用缓存
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11.3" data-path="C02-Users/Address/UserAddressManagement.html">
            
                
                    <a href="../C02-Users/Address/UserAddressManagement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.3.</b>
                        
                        用户地址管理
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="C03-Goods/index.html">
            
                
                    <a href="../C03-Goods/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        商品部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="C03-Goods/DatabaseDesign.html">
            
                
                    <a href="../C03-Goods/DatabaseDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        数据表设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="C03-Goods/FastDFS.html">
            
                
                    <a href="../C03-Goods/FastDFS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        FastDFS分布式文件系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="C03-Goods/Docker/index.html">
            
                
                    <a href="../C03-Goods/Docker/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Docker使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="C03-Goods/Docker/Introduce.html">
            
                
                    <a href="../C03-Goods/Docker/Introduce.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.1.</b>
                        
                        Docker简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="C03-Goods/Docker/InstallAndOperations.html">
            
                
                    <a href="../C03-Goods/Docker/InstallAndOperations.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.2.</b>
                        
                        安装与操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="C03-Goods/FastDFSDocker.html">
            
                
                    <a href="../C03-Goods/FastDFSDocker.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        使用Docker安装FastDFS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="C03-Goods/FastDFSClientAndDjangoFileSystem.html">
            
                
                    <a href="../C03-Goods/FastDFSClientAndDjangoFileSystem.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        FastDFS客户端与自定义文件存储系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="C03-Goods/CKEditor.html">
            
                
                    <a href="../C03-Goods/CKEditor.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        CKEditor富文本编辑器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="C03-Goods/ImportGoodsData.html">
            
                
                    <a href="../C03-Goods/ImportGoodsData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        添加测试数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="C03-Goods/FreezeHTML.html">
            
                
                    <a href="../C03-Goods/FreezeHTML.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        页面静态化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="C03-Goods/DjangoCrontab.html">
            
                
                    <a href="../C03-Goods/DjangoCrontab.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        定时任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="C03-Goods/GenerateIndexHTMLScript.html">
            
                
                    <a href="../C03-Goods/GenerateIndexHTMLScript.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        静态化首页的手动脚本
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="C03-Goods/GoodsDetail.html">
            
                
                    <a href="../C03-Goods/GoodsDetail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.11.</b>
                        
                        商品详情页面
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="C03-Goods/HotSaleGoods.html">
            
                
                    <a href="../C03-Goods/HotSaleGoods.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.12.</b>
                        
                        热销商品
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.13" data-path="C03-Goods/UserBrowseHistory.html">
            
                
                    <a href="../C03-Goods/UserBrowseHistory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.13.</b>
                        
                        用户浏览历史记录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.14" data-path="C03-Goods/GoodsList.html">
            
                
                    <a href="../C03-Goods/GoodsList.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.14.</b>
                        
                        商品列表页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.15" data-path="C03-Goods/GoodsSearch.html">
            
                
                    <a href="../C03-Goods/GoodsSearch.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.15.</b>
                        
                        商品搜索
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="C04-Cart/index.html">
            
                
                    <a href="../C04-Cart/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        购物车部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="C04-Cart/DataStructureDesign.html">
            
                
                    <a href="../C04-Cart/DataStructureDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        购物车数据存储设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="C04-Cart/Implement.html">
            
                
                    <a href="../C04-Cart/Implement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        购物车实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="C04-Cart/MergeCart.html">
            
                
                    <a href="../C04-Cart/MergeCart.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        登录合并购物车
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="C05-Order/index.html">
            
                
                    <a href="../C05-Order/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        订单部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="C05-Order/OrderDBModel.html">
            
                
                    <a href="../C05-Order/OrderDBModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        订单数据库设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="C05-Order/PlaceOrder.html">
            
                
                    <a href="../C05-Order/PlaceOrder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        订单结算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="C05-Order/SaveOrder.html">
            
                
                    <a href="../C05-Order/SaveOrder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        保存订单
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="C05-Order/OrderSuccess.html">
            
                
                    <a href="../C05-Order/OrderSuccess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        下单成功
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="C06-Pay/index.html">
            
                
                    <a href="../C06-Pay/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        支付宝支付
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="C06-Pay/Alipay.html">
            
                
                    <a href="../C06-Pay/Alipay.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        接入支付宝
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="C06-Pay/Paying.html">
            
                
                    <a href="../C06-Pay/Paying.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        发起支付
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="C06-Pay/PaymentResult.html">
            
                
                    <a href="../C06-Pay/PaymentResult.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        保存支付结果
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="C07-Xadmin.html">
            
                
                    <a href="../C07-Xadmin.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        Xadmin
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="C08-Permission.html">
            
                
                    <a href="../C08-Permission.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        用户权限控制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9" data-path="C09-Database/index.html">
            
                
                    <a href="../C09-Database/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        数据库读写分离
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="C09-Database/MasterSlave.html">
            
                
                    <a href="../C09-Database/MasterSlave.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        主从同步配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="C09-Database/ReadWriteSeparate.html">
            
                
                    <a href="../C09-Database/ReadWriteSeparate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        Django数据库读写分离
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="C10-Deploy.html">
            
                
                    <a href="../C10-Deploy.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        Django部署
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >美多商城</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x6CE8;&#x518C;">&#x6CE8;&#x518C;</h1>
<p>&#x521B;&#x5EFA;&#x597D;&#x7528;&#x6237;&#x6A21;&#x578B;&#x7C7B;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x5F00;&#x59CB;&#x6765;&#x5B9E;&#x73B0;&#x7B2C;&#x4E00;&#x4E2A;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x2014;&#x2014;&#x7528;&#x6237;&#x6CE8;&#x518C;&#x3002;</p>
<h2 id="1--&#x8BBE;&#x8BA1;&#x63A5;&#x53E3;&#x7684;&#x601D;&#x8DEF;">1.  &#x8BBE;&#x8BA1;&#x63A5;&#x53E3;&#x7684;&#x601D;&#x8DEF;</h2>
<ul>
<li><p>&#x5206;&#x6790;&#x8981;&#x5B9E;&#x73B0;&#x7684;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#xFF0C;&#x660E;&#x786E;&#x5728;&#x8FD9;&#x4E2A;&#x4E1A;&#x52A1;&#x4E2D;&#x9700;&#x8981;&#x6D89;&#x53CA;&#x5230;&#x51E0;&#x4E2A;&#x76F8;&#x5173;&#x5B50;&#x4E1A;&#x52A1;&#xFF0C;&#x5C06;&#x6BCF;&#x4E2A;&#x5B50;&#x4E1A;&#x52A1;&#x5F53;&#x505A;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x6765;&#x8BBE;&#x8BA1;&#x3002;</p>
</li>
<li><p>&#x5206;&#x6790;&#x63A5;&#x53E3;&#x7684;&#x529F;&#x80FD;&#x4EFB;&#x52A1;&#xFF0C;&#x660E;&#x786E;&#x63A5;&#x53E3;&#x7684;&#x8BBF;&#x95EE;&#x65B9;&#x5F0F;&#x4E0E;&#x8FD4;&#x56DE;&#x6570;&#x636E;&#xFF1A;</p>
<ul>
<li>&#x63A5;&#x53E3;&#x7684;&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#xFF0C;&#x5982;GET &#x3001;POST &#x3001;PUT&#x7B49;</li>
<li>&#x63A5;&#x53E3;&#x7684;URL&#x8DEF;&#x5F84;&#x5B9A;&#x4E49;</li>
<li>&#x9700;&#x8981;&#x524D;&#x7AEF;&#x4F20;&#x9012;&#x7684;&#x6570;&#x636E;&#x53CA;&#x6570;&#x636E;&#x683C;&#x5F0F;&#xFF08;&#x5982;&#x8DEF;&#x5F84;&#x53C2;&#x6570;&#x3001;&#x67E5;&#x8BE2;&#x5B57;&#x7B26;&#x4E32;&#x3001;&#x8BF7;&#x6C42;&#x4F53;&#x8868;&#x5355;&#x3001;JSON&#x7B49;&#xFF09;</li>
<li>&#x8FD4;&#x56DE;&#x7ED9;&#x524D;&#x7AEF;&#x7684;&#x6570;&#x636E;&#x53CA;&#x6570;&#x636E;&#x683C;&#x5F0F;</li>
</ul>
</li>
</ul>
<p>&#x5728;&#x524D;&#x540E;&#x7AEF;&#x5206;&#x79BB;&#x7684;&#x5E94;&#x7528;&#x6A21;&#x5F0F;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x4F5C;&#x4E3A;&#x540E;&#x7AEF;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x8BBE;&#x8BA1;&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x4E0D;&#x7528;&#x8003;&#x8651;&#x8FD4;&#x56DE;&#x7ED9;&#x524D;&#x7AEF;&#x6570;&#x636E;&#x540E;&#xFF0C;&#x524D;&#x7AEF;&#x5982;&#x4F55;&#x5904;&#x7406;&#xFF0C;&#x8FD9;&#x662F;&#x524D;&#x7AEF;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x7684;&#x5DE5;&#x4F5C;&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x660E;&#x786E;&#x6211;&#x4EEC;&#x8981;&#x4FDD;&#x5B58;&#x7684;&#x6216;&#x8005;&#x8981;&#x8FD4;&#x56DE;&#x7684;&#x662F;&#x4EC0;&#x4E48;&#x6570;&#x636E;&#x5373;&#x53EF;&#x3002;</p>
<p>&#x660E;&#x786E;&#x4E0A;&#x8FF0;&#x6BCF;&#x4E00;&#x70B9;&#x540E;&#xFF0C;&#x5373;&#x53EF;&#x5F00;&#x59CB;&#x7F16;&#x5199;&#x63A5;&#x53E3;&#x3002;</p>
<p>&#x5728;&#x7528;&#x6237;&#x6CE8;&#x518C;&#x4E2D;&#xFF0C;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4E00;&#x4E0B;&#x63A5;&#x53E3;&#xFF1A;</p>
<ul>
<li>&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;</li>
<li>&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;</li>
<li>&#x7528;&#x6237;&#x540D;&#x5224;&#x65AD;&#x662F;&#x5426;&#x5B58;&#x5728;</li>
<li>&#x624B;&#x673A;&#x53F7;&#x5224;&#x65AD;&#x662F;&#x5426;&#x5B58;&#x5728;</li>
<li>&#x6CE8;&#x518C;&#x4FDD;&#x5B58;&#x7528;&#x6237;&#x6570;&#x636E;</li>
</ul>
<p>&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;&#x3001;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;&#x8003;&#x8651;&#x5230;&#x540E;&#x7EED;&#x53EF;&#x80FD;&#x4F1A;&#x5728;&#x5176;&#x4ED6;&#x4E1A;&#x52A1;&#x4E2D;&#x4E5F;&#x7528;&#x5230;&#xFF0C;&#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x5C06;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;&#x72EC;&#x7ACB;&#xFF0C;<strong>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5E94;&#x7528;&#x65B0;&#x5E94;&#x7528;verifications&#xFF0C;&#x5728;&#x6B64;&#x5E94;&#x7528;&#x4E2D;&#x5B9E;&#x73B0;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;&#x3001;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;</strong>&#x3002;</p>
<h2 id="2--&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;">2.  &#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;</h2>
<h4 id="&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;">&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;</h4>
<p>&#x8BBF;&#x95EE;&#x65B9;&#x5F0F;&#xFF1A; GET   /image_codes/{image_code_id}/</p>
<p>&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>image_code_id</td>
<td>uuid&#x5B57;&#x7B26;&#x4E32;</td>
<td>&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;&#x7F16;&#x53F7;</td>
</tr>
</tbody>
</table>
<p>&#x8FD4;&#x56DE;&#x6570;&#x636E;&#xFF1A;</p>
<p>&#x9A8C;&#x8BC1;&#x7801;&#x56FE;&#x7247;</p>
<pre><code class="lang-python"><span class="hljs-comment"># verifications/views.py</span>
<span class="hljs-comment"># url(r&apos;image_codes/(?P&lt;image_code_id&gt;.+)/$&apos;, views.ImageCodeView.as_view()),</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ImageCodeView</span><span class="hljs-params">(APIView)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;
    &quot;&quot;&quot;</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get</span><span class="hljs-params">(self, request, image_code_id)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x83B7;&#x53D6;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;
        &quot;&quot;&quot;</span>

        <span class="hljs-comment"># &#x751F;&#x6210;&#x9A8C;&#x8BC1;&#x7801;&#x56FE;&#x7247;</span>
        text, image = captcha.generate_captcha()

        redis_conn = get_redis_connection(<span class="hljs-string">&quot;verify_codes&quot;</span>)
        redis_conn.setex(<span class="hljs-string">&quot;img_%s&quot;</span> % code_id, constants.IMAGE_CODE_REDIS_EXPIRES, text)

        <span class="hljs-keyword">return</span> HttpResponse(image, content_type=<span class="hljs-string">&quot;images/jpg&quot;</span>)
</code></pre>
<p>&#x8BF4;&#x660E;&#xFF1A;</p>
<p><strong>django-redis&#x63D0;&#x4F9B;&#x4E86;get_redis_connection&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x901A;&#x8FC7;&#x8C03;&#x7528;get_redis_connection&#x65B9;&#x6CD5;&#x4F20;&#x9012;redis&#x7684;&#x914D;&#x7F6E;&#x540D;&#x79F0;&#x53EF;&#x83B7;&#x53D6;&#x5230;redis&#x7684;&#x8FDE;&#x63A5;&#x5BF9;&#x8C61;&#xFF0C;&#x901A;&#x8FC7;redis&#x8FDE;&#x63A5;&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x6267;&#x884C;redis&#x547D;&#x4EE4;&#x3002;</strong></p>
<p>&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x65B0;&#x7684;redis&#x914D;&#x7F6E;&#xFF0C;&#x7528;&#x4E8E;&#x5B58;&#x653E;&#x9A8C;&#x8BC1;&#x7801;&#x6570;&#x636E;</p>
<pre><code class="lang-python">CACHES = {
    <span class="hljs-string">&quot;default&quot;</span>: {
        <span class="hljs-string">&quot;BACKEND&quot;</span>: <span class="hljs-string">&quot;django_redis.cache.RedisCache&quot;</span>,
        <span class="hljs-string">&quot;LOCATION&quot;</span>: <span class="hljs-string">&quot;redis://10.211.55.5:6379/0&quot;</span>,
        <span class="hljs-string">&quot;OPTIONS&quot;</span>: {
            <span class="hljs-string">&quot;CLIENT_CLASS&quot;</span>: <span class="hljs-string">&quot;django_redis.client.DefaultClient&quot;</span>,
        }
    },
    <span class="hljs-string">&quot;session&quot;</span>: {
        <span class="hljs-string">&quot;BACKEND&quot;</span>: <span class="hljs-string">&quot;django_redis.cache.RedisCache&quot;</span>,
        <span class="hljs-string">&quot;LOCATION&quot;</span>: <span class="hljs-string">&quot;redis://10.211.55.5:6379/1&quot;</span>,
        <span class="hljs-string">&quot;OPTIONS&quot;</span>: {
            <span class="hljs-string">&quot;CLIENT_CLASS&quot;</span>: <span class="hljs-string">&quot;django_redis.client.DefaultClient&quot;</span>,
        }
    },
    <span class="hljs-string">&quot;verify_codes&quot;</span>: {
        <span class="hljs-string">&quot;BACKEND&quot;</span>: <span class="hljs-string">&quot;django_redis.cache.RedisCache&quot;</span>,
        <span class="hljs-string">&quot;LOCATION&quot;</span>: <span class="hljs-string">&quot;redis://10.211.55.5:6379/2&quot;</span>,
        <span class="hljs-string">&quot;OPTIONS&quot;</span>: {
            <span class="hljs-string">&quot;CLIENT_CLASS&quot;</span>: <span class="hljs-string">&quot;django_redis.client.DefaultClient&quot;</span>,
        }
    }
}
</code></pre>
<h4 id="&#x524D;&#x7AEF;vue&#x4EE3;&#x7801;&#xFF1A;">&#x524D;&#x7AEF;Vue&#x4EE3;&#x7801;&#xFF1A;</h4>
<p>js/register.js</p>
<pre><code class="lang-js">data: {
    ...
    image_code_id: <span class="hljs-string">&apos;&apos;</span>,  <span class="hljs-comment">// &#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;&#x7F16;&#x53F7;</span>
    image_code_url: <span class="hljs-string">&apos;&apos;</span>,  <span class="hljs-comment">// &#x9A8C;&#x8BC1;&#x7801;&#x56FE;&#x7247;&#x8DEF;&#x5F84;</span>
},
mounted: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.generate_image_code();
},
methods: {
    <span class="hljs-comment">// &#x751F;&#x6210;uuid</span>
    generate_uuid: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">var</span> d = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime();
        <span class="hljs-keyword">if</span>(<span class="hljs-built_in">window</span>.performance &amp;&amp; <span class="hljs-keyword">typeof</span> <span class="hljs-built_in">window</span>.performance.now === <span class="hljs-string">&quot;function&quot;</span>){
            d += performance.now(); <span class="hljs-comment">//use high-precision timer if available</span>
        }
        <span class="hljs-keyword">var</span> uuid = <span class="hljs-string">&apos;xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx&apos;</span>.replace(<span class="hljs-regexp">/[xy]/g</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">c</span>) </span>{
            <span class="hljs-keyword">var</span> r = (d + <span class="hljs-built_in">Math</span>.random()*<span class="hljs-number">16</span>)%<span class="hljs-number">16</span> | <span class="hljs-number">0</span>;
            d = <span class="hljs-built_in">Math</span>.floor(d/<span class="hljs-number">16</span>);
            <span class="hljs-keyword">return</span> (c ==<span class="hljs-string">&apos;x&apos;</span> ? r : (r&amp;<span class="hljs-number">0x3</span>|<span class="hljs-number">0x8</span>)).toString(<span class="hljs-number">16</span>);
        });
        <span class="hljs-keyword">return</span> uuid;
    },
    <span class="hljs-comment">// &#x751F;&#x6210;&#x4E00;&#x4E2A;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;&#x7684;&#x7F16;&#x53F7;&#xFF0C;&#x5E76;&#x8BBE;&#x7F6E;&#x9875;&#x9762;&#x4E2D;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;img&#x6807;&#x7B7E;&#x7684;src&#x5C5E;&#x6027;</span>
    generate_image_code: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-comment">// &#x751F;&#x6210;&#x4E00;&#x4E2A;&#x7F16;&#x53F7;</span>
        <span class="hljs-comment">// &#x4E25;&#x683C;&#x4E00;&#x70B9;&#x7684;&#x4F7F;&#x7528;uuid&#x4FDD;&#x8BC1;&#x7F16;&#x53F7;&#x552F;&#x4E00;&#xFF0C; &#x4E0D;&#x662F;&#x5F88;&#x4E25;&#x8C28;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x65F6;&#x95F4;&#x6233;</span>
        <span class="hljs-keyword">this</span>.image_code_id = <span class="hljs-keyword">this</span>.generate_uuid();

        <span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x9875;&#x9762;&#x4E2D;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;img&#x6807;&#x7B7E;&#x7684;src&#x5C5E;&#x6027;</span>
        <span class="hljs-keyword">this</span>.image_code_url = <span class="hljs-string">&apos;http://127.0.0.1:8000&apos;</span> + <span class="hljs-string">&quot;/image_codes/&quot;</span> + <span class="hljs-keyword">this</span>.image_code_id + <span class="hljs-string">&quot;/&quot;</span>;
    },
    ...
}
</code></pre>
<h2 id="2--&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;">2.  &#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;</h2>
<h4 id="&#x4E1A;&#x52A1;&#x5904;&#x7406;&#x6D41;&#x7A0B;">&#x4E1A;&#x52A1;&#x5904;&#x7406;&#x6D41;&#x7A0B;</h4>
<ol>
<li>&#x68C0;&#x67E5;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;</li>
<li>&#x68C0;&#x67E5;&#x662F;&#x5426;&#x5728;60s&#x5185;&#x6709;&#x53D1;&#x9001;&#x8BB0;&#x5F55;</li>
<li>&#x751F;&#x6210;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;</li>
<li>&#x4FDD;&#x5B58;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;&#x4E0E;&#x53D1;&#x9001;&#x8BB0;&#x5F55;</li>
<li>&#x53D1;&#x9001;&#x77ED;&#x4FE1;</li>
</ol>
<h4 id="&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;">&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;</h4>
<p>&#x8BBF;&#x95EE;&#x65B9;&#x5F0F;&#xFF1A; GET   /sms_codes/{mobile}/?image_code_id=xxx&amp;text=xxx</p>
<p>&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>mobile</td>
<td>str</td>
<td>&#x624B;&#x673A;&#x53F7;</td>
</tr>
<tr>
<td>image_code_id</td>
<td>uuid&#x5B57;&#x7B26;&#x4E32;</td>
<td>&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;&#x7F16;&#x53F7;</td>
</tr>
<tr>
<td>text</td>
<td>str</td>
<td>&#x7528;&#x6237;&#x8F93;&#x5165;&#x7684;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;</td>
</tr>
</tbody>
</table>
<p>&#x8FD4;&#x56DE;&#x6570;&#x636E;&#xFF1A;</p>
<p>json</p>
<table>
<thead>
<tr>
<th>&#x8FD4;&#x56DE;&#x503C;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>message</td>
<td>str</td>
<td>OK&#xFF0C;&#x53D1;&#x9001;&#x6210;&#x529F;</td>
</tr>
</tbody>
</table>
<p>&#x5B9A;&#x4E49;&#x5E8F;&#x5217;&#x5316;&#x5668;&#xFF0C;&#x7528;&#x4EE5;&#x6821;&#x9A8C;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ImageCodeCheckSerializer</span><span class="hljs-params">(serializers.Serializer)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;&#x6821;&#x9A8C;&#x5E8F;&#x5217;&#x5316;&#x5668;
    &quot;&quot;&quot;</span>
    image_code_id = serializers.UUIDField()
    text = serializers.CharField(max_length=<span class="hljs-number">4</span>, min_length=<span class="hljs-number">4</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">validate</span><span class="hljs-params">(self, attrs)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x6821;&#x9A8C;
        &quot;&quot;&quot;</span>
        image_code_id = attrs[<span class="hljs-string">&apos;image_code_id&apos;</span>]
        text = attrs[<span class="hljs-string">&apos;text&apos;</span>]
        <span class="hljs-comment"># &#x67E5;&#x8BE2;&#x771F;&#x5B9E;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;</span>
        redis_conn = get_redis_connection(<span class="hljs-string">&apos;verify_codes&apos;</span>)
        real_image_code_text = redis_conn.get(<span class="hljs-string">&apos;img_%s&apos;</span> % image_code_id)
        <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> real_image_code_text:
            <span class="hljs-keyword">raise</span> serializers.ValidationError(<span class="hljs-string">&apos;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;&#x65E0;&#x6548;&apos;</span>)

        <span class="hljs-comment"># &#x5220;&#x9664;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;</span>
        <span class="hljs-keyword">try</span>:
            redis_conn.delete(<span class="hljs-string">&apos;img_%s&apos;</span> % image_code_id)
        <span class="hljs-keyword">except</span> RedisError <span class="hljs-keyword">as</span> e:
            logger.error(e)

        <span class="hljs-comment"># &#x6BD4;&#x8F83;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;</span>
        real_image_code_text = real_image_code_text.decode()
        <span class="hljs-keyword">if</span> real_image_code_text.lower() != text.lower():
            <span class="hljs-keyword">raise</span> serializers.ValidationError(<span class="hljs-string">&apos;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;&#x9519;&#x8BEF;&apos;</span>)

        <span class="hljs-comment"># &#x5224;&#x65AD;&#x662F;&#x5426;&#x5728;60s&#x5185;</span>
        mobile = self.context[<span class="hljs-string">&apos;view&apos;</span>].kwargs[<span class="hljs-string">&apos;mobile&apos;</span>]
        send_flag = redis_conn.get(<span class="hljs-string">&quot;send_flag_%s&quot;</span> % mobile)
        <span class="hljs-keyword">if</span> send_flag:
            <span class="hljs-keyword">raise</span> serializers.ValidationError(<span class="hljs-string">&apos;&#x8BF7;&#x6C42;&#x6B21;&#x6570;&#x8FC7;&#x4E8E;&#x9891;&#x7E41;&apos;</span>)

        <span class="hljs-keyword">return</span> attrs
</code></pre>
<p>&#x89C6;&#x56FE;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SMSCodeView</span><span class="hljs-params">(GenericAPIView)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;
    &quot;&quot;&quot;</span>
    serializer_class = serializers.ImageCodeCheckSerializer

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get</span><span class="hljs-params">(self, request, mobile)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x521B;&#x5EFA;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;
        &quot;&quot;&quot;</span>
        <span class="hljs-comment"># &#x5224;&#x65AD;&#x56FE;&#x7247;&#x9A8C;&#x8BC1;&#x7801;, &#x5224;&#x65AD;&#x662F;&#x5426;&#x5728;60s&#x5185;</span>
        serializer = self.get_serializer(data=request.query_params)
        serializer.is_valid(raise_exception=<span class="hljs-keyword">True</span>)

        <span class="hljs-comment"># &#x751F;&#x6210;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;</span>
        sms_code = <span class="hljs-string">&quot;%06d&quot;</span> % random.randint(<span class="hljs-number">0</span>, <span class="hljs-number">999999</span>)

        <span class="hljs-comment"># &#x4FDD;&#x5B58;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;&#x4E0E;&#x53D1;&#x9001;&#x8BB0;&#x5F55;</span>
        redis_conn = get_redis_connection(<span class="hljs-string">&apos;verify_codes&apos;</span>)
        pl = redis_conn.pipeline()
        pl.multi()
        pl.setex(<span class="hljs-string">&quot;sms_%s&quot;</span> % mobile, constants.SMS_CODE_REDIS_EXPIRES, sms_code)
        pl.setex(<span class="hljs-string">&quot;send_flag_%s&quot;</span> % mobile, constants.SEND_SMS_CODE_INTERVAL, <span class="hljs-number">1</span>)
        pl.execute()

        <span class="hljs-comment"># &#x53D1;&#x9001;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;</span>
        sms_code_expires = str(constants.SMS_CODE_REDIS_EXPIRES // <span class="hljs-number">60</span>)
        ccp = CCP()
        ccp.send_template_sms(mobile, [code, expires], SMS_CODE_TEMP_ID)

        <span class="hljs-keyword">return</span> Response({<span class="hljs-string">&quot;message&quot;</span>: <span class="hljs-string">&quot;OK&quot;</span>}, status.HTTP_200_OK)
</code></pre>
<h4 id="&#x4F7F;&#x7528;celery&#x5B8C;&#x6210;&#x53D1;&#x9001;&#x77ED;&#x4FE1;">&#x4F7F;&#x7528;Celery&#x5B8C;&#x6210;&#x53D1;&#x9001;&#x77ED;&#x4FE1;</h4>
<p>&#x5728;<code>&#x5DE5;&#x7A0B;&#x76EE;&#x5F55;/meiduo_mall</code>&#x4E0B;&#x521B;&#x5EFA;celery_tasks&#x7528;&#x4E8E;&#x4FDD;&#x5B58;celery&#x5F02;&#x6B65;&#x4EFB;&#x52A1;&#x3002;</p>
<p>&#x5728;celery_tasks&#x76EE;&#x5F55;&#x4E0B;&#x521B;&#x5EFA;config.py&#x6587;&#x4EF6;&#xFF0C;&#x7528;&#x4E8E;&#x4FDD;&#x5B58;celery&#x7684;&#x914D;&#x7F6E;&#x4FE1;&#x606F;</p>
<pre><code class="lang-python">broker_url = <span class="hljs-string">&quot;redis://127.0.0.1/14&quot;</span>
result_backend = <span class="hljs-string">&quot;redis://127.0.0.1/15&quot;</span>
</code></pre>
<p>&#x5728;celery_tasks&#x76EE;&#x5F55;&#x4E0B;&#x521B;&#x5EFA;main.py&#x6587;&#x4EF6;&#xFF0C;&#x7528;&#x4E8E;&#x4F5C;&#x4E3A;celery&#x7684;&#x542F;&#x52A8;&#x6587;&#x4EF6;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> celery <span class="hljs-keyword">import</span> Celery

<span class="hljs-comment"># &#x4E3A;celery&#x4F7F;&#x7528;django&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x8FDB;&#x884C;&#x8BBE;&#x7F6E;</span>
<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.getenv(<span class="hljs-string">&apos;DJANGO_SETTINGS_MODULE&apos;</span>):
    os.environ[<span class="hljs-string">&apos;DJANGO_SETTINGS_MODULE&apos;</span>] = <span class="hljs-string">&apos;meiduo_mall.settings.dev&apos;</span>

<span class="hljs-comment"># &#x521B;&#x5EFA;celery&#x5E94;&#x7528;</span>
app = Celery(<span class="hljs-string">&apos;meiduo&apos;</span>)

<span class="hljs-comment"># &#x5BFC;&#x5165;celery&#x914D;&#x7F6E;</span>
app.config_from_object(<span class="hljs-string">&apos;celery_tasks.config&apos;</span>)

<span class="hljs-comment"># &#x81EA;&#x52A8;&#x6CE8;&#x518C;celery&#x4EFB;&#x52A1;</span>
app.autodiscover_tasks([<span class="hljs-string">&apos;celery_tasks.sms&apos;</span>])
</code></pre>
<p>&#x5728;celery_tasks&#x76EE;&#x5F55;&#x4E0B;&#x521B;&#x5EFA;sms/tasks.py&#x76EE;&#x5F55;&#x6587;&#x4EF6;&#xFF0C;&#x7528;&#x4E8E;&#x4FDD;&#x5B58;&#x53D1;&#x9001;&#x77ED;&#x4FE1;&#x7684;&#x5F02;&#x6B65;&#x4EFB;&#x52A1;</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> logging

<span class="hljs-keyword">from</span> celery_tasks.main <span class="hljs-keyword">import</span> app
<span class="hljs-keyword">from</span> .yuntongxun.sms <span class="hljs-keyword">import</span> CCP

logger = logging.getLogger(<span class="hljs-string">&quot;django&quot;</span>)

<span class="hljs-comment"># &#x9A8C;&#x8BC1;&#x7801;&#x77ED;&#x4FE1;&#x6A21;&#x677F;</span>
SMS_CODE_TEMP_ID = <span class="hljs-number">1</span>

<span class="hljs-decorator">@app.task(name=&apos;send_sms_code&apos;)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">send_sms_code</span><span class="hljs-params">(mobile, code, expires)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x53D1;&#x9001;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;
    :param mobile: &#x624B;&#x673A;&#x53F7;
    :param code: &#x9A8C;&#x8BC1;&#x7801;
    :param expires: &#x6709;&#x6548;&#x671F;
    :return: None
    &quot;&quot;&quot;</span>

    <span class="hljs-keyword">try</span>:
        ccp = CCP()
        result = ccp.send_template_sms(mobile, [code, expires], SMS_CODE_TEMP_ID)
    <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
        logger.error(<span class="hljs-string">&quot;&#x53D1;&#x9001;&#x9A8C;&#x8BC1;&#x7801;&#x77ED;&#x4FE1;[&#x5F02;&#x5E38;][ mobile: %s, message: %s ]&quot;</span> % (mobile, e))
    <span class="hljs-keyword">else</span>:
        <span class="hljs-keyword">if</span> result == <span class="hljs-number">0</span>:
            logger.info(<span class="hljs-string">&quot;&#x53D1;&#x9001;&#x9A8C;&#x8BC1;&#x7801;&#x77ED;&#x4FE1;[&#x6B63;&#x5E38;][ mobile: %s ]&quot;</span> % mobile)
        <span class="hljs-keyword">else</span>:
            logger.warning(<span class="hljs-string">&quot;&#x53D1;&#x9001;&#x9A8C;&#x8BC1;&#x7801;&#x77ED;&#x4FE1;[&#x5931;&#x8D25;][ mobile: %s ]&quot;</span> % mobile)
</code></pre>
<p>&#x5728;verifications/views.py&#x4E2D;&#x6539;&#x5199;SMSCodeView&#x89C6;&#x56FE;&#xFF0C;&#x4F7F;&#x7528;celery&#x5F02;&#x6B65;&#x4EFB;&#x52A1;&#x53D1;&#x9001;&#x77ED;&#x4FE1;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SMSCodeView</span><span class="hljs-params">(GenericAPIView)</span>:</span>
    ...
        <span class="hljs-comment"># &#x53D1;&#x9001;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;</span>
        sms_code_expires = str(constants.SMS_CODE_REDIS_EXPIRES // <span class="hljs-number">60</span>)
        sms_tasks.send_sms_code.delay(mobile, sms_code, sms_code_expires)

        <span class="hljs-keyword">return</span> Response({<span class="hljs-string">&quot;message&quot;</span>: <span class="hljs-string">&quot;OK&quot;</span>}, status.HTTP_200_OK)
</code></pre>
<h2 id="3--&#x7528;&#x6237;&#x540D;&#x4E0E;&#x624B;&#x673A;&#x53F7;&#x662F;&#x5426;&#x5B58;&#x5728;&#x7684;&#x5224;&#x65AD;">3.  &#x7528;&#x6237;&#x540D;&#x4E0E;&#x624B;&#x673A;&#x53F7;&#x662F;&#x5426;&#x5B58;&#x5728;&#x7684;&#x5224;&#x65AD;</h2>
<h3 id="&#x5224;&#x65AD;&#x7528;&#x6237;&#x540D;&#x662F;&#x5426;&#x5B58;&#x5728;">&#x5224;&#x65AD;&#x7528;&#x6237;&#x540D;&#x662F;&#x5426;&#x5B58;&#x5728;</h3>
<h4 id="&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;">&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;</h4>
<p>&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#xFF1A; GET  <code>usernames/(?P&lt;username&gt;\w{5,20})/count/</code></p>
<p>&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>username</td>
<td>str</td>
<td>&#x7528;&#x6237;&#x540D;</td>
</tr>
</tbody>
</table>
<p>&#x8FD4;&#x56DE;&#x6570;&#x636E;&#xFF1A;</p>
<p>json</p>
<table>
<thead>
<tr>
<th>&#x8FD4;&#x56DE;&#x503C;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>username</td>
<td>str</td>
<td>&#x7528;&#x6237;&#x540D;</td>
</tr>
<tr>
<td>count</td>
<td>int</td>
<td>&#x6570;&#x91CF;</td>
</tr>
</tbody>
</table>
<pre><code class="lang-python"><span class="hljs-comment"># users/views.py</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UsernameCountView</span><span class="hljs-params">(APIView)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x7528;&#x6237;&#x540D;&#x6570;&#x91CF;
    &quot;&quot;&quot;</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get</span><span class="hljs-params">(self, request, username)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x83B7;&#x53D6;&#x6307;&#x5B9A;&#x7528;&#x6237;&#x540D;&#x6570;&#x91CF;
        &quot;&quot;&quot;</span>
        count = User.objects.filter(username=username).count()

        data = {
            <span class="hljs-string">&apos;username&apos;</span>: username,
            <span class="hljs-string">&apos;count&apos;</span>: count
        }

        <span class="hljs-keyword">return</span> Response(data)
</code></pre>
<h4 id="&#x5224;&#x65AD;&#x624B;&#x673A;&#x53F7;&#x662F;&#x5426;&#x5B58;&#x5728;&#xFF1A;">&#x5224;&#x65AD;&#x624B;&#x673A;&#x53F7;&#x662F;&#x5426;&#x5B58;&#x5728;&#xFF1A;</h4>
<h4 id="&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;">&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;</h4>
<p>&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#xFF1A; GET <code>mobiles/(?P&lt;mobile&gt;1[345789]\d{9})/count</code></p>
<p>&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>mobile</td>
<td>str</td>
<td>&#x624B;&#x673A;&#x53F7;</td>
</tr>
</tbody>
</table>
<p>&#x8FD4;&#x56DE;&#x6570;&#x636E;&#xFF1A;</p>
<p>json</p>
<table>
<thead>
<tr>
<th>&#x8FD4;&#x56DE;&#x503C;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>mobile</td>
<td>str</td>
<td>&#x624B;&#x673A;&#x53F7;</td>
</tr>
<tr>
<td>count</td>
<td>int</td>
<td>&#x6570;&#x91CF;</td>
</tr>
</tbody>
</table>
<pre><code class="lang-python"><span class="hljs-comment"># users/views.py</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MobileCountView</span><span class="hljs-params">(APIView)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x624B;&#x673A;&#x53F7;&#x6570;&#x91CF;
    &quot;&quot;&quot;</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get</span><span class="hljs-params">(self, request, mobile)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x83B7;&#x53D6;&#x6307;&#x5B9A;&#x624B;&#x673A;&#x53F7;&#x6570;&#x91CF;
        &quot;&quot;&quot;</span>
        count = User.objects.filter(mobile=mobile).count()

        data = {
            <span class="hljs-string">&apos;mobile&apos;</span>: mobile,
            <span class="hljs-string">&apos;count&apos;</span>: count
        }

        <span class="hljs-keyword">return</span> Response(data)
</code></pre>
<h2 id="4--&#x6CE8;&#x518C;">4.  &#x6CE8;&#x518C;</h2>
<h4 id="&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;">&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;</h4>
<p>&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#xFF1A; POST  <code>/users/</code></p>
<p>&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;&#x540D;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>username</td>
<td>str</td>
<td>&#x7528;&#x6237;&#x540D;</td>
</tr>
<tr>
<td>password</td>
<td>str</td>
<td>&#x5BC6;&#x7801;</td>
</tr>
<tr>
<td>password2</td>
<td>str</td>
<td>&#x786E;&#x8BA4;&#x5BC6;&#x7801;</td>
</tr>
<tr>
<td>sms_code</td>
<td>str</td>
<td>&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;</td>
</tr>
<tr>
<td>mobile</td>
<td>str</td>
<td>&#x624B;&#x673A;&#x53F7;</td>
</tr>
<tr>
<td>allow</td>
<td>str</td>
<td>&#x662F;&#x5426;&#x540C;&#x610F;&#x7528;&#x6237;&#x534F;&#x8BAE;</td>
</tr>
</tbody>
</table>
<p>&#x8FD4;&#x56DE;&#x6570;&#x636E;&#xFF1A;</p>
<p>json  &#x7528;&#x6237;&#x5BF9;&#x8C61;&#x6A21;&#x578B;&#x6570;&#x636E;</p>
<p>&#x521B;&#x5EFA;&#x5E8F;&#x5217;&#x5316;&#x5668;&#x5BF9;&#x8C61;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CreateUserSerializer</span><span class="hljs-params">(serializers.ModelSerializer)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x521B;&#x5EFA;&#x7528;&#x6237;&#x5E8F;&#x5217;&#x5316;&#x5668;
    &quot;&quot;&quot;</span>
    password2 = serializers.CharField(label=<span class="hljs-string">&apos;&#x786E;&#x8BA4;&#x5BC6;&#x7801;&apos;</span>, required=<span class="hljs-keyword">True</span>, allow_null=<span class="hljs-keyword">False</span>, allow_blank=<span class="hljs-keyword">False</span>, write_only=<span class="hljs-keyword">True</span>)
    sms_code = serializers.CharField(label=<span class="hljs-string">&apos;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;&apos;</span>, required=<span class="hljs-keyword">True</span>, allow_null=<span class="hljs-keyword">False</span>, allow_blank=<span class="hljs-keyword">False</span>, write_only=<span class="hljs-keyword">True</span>)
    allow = serializers.CharField(label=<span class="hljs-string">&apos;&#x540C;&#x610F;&#x534F;&#x8BAE;&apos;</span>, required=<span class="hljs-keyword">True</span>, allow_null=<span class="hljs-keyword">False</span>, allow_blank=<span class="hljs-keyword">False</span>, write_only=<span class="hljs-keyword">True</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">validate_mobile</span><span class="hljs-params">(self, value)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;&#x9A8C;&#x8BC1;&#x624B;&#x673A;&#x53F7;&quot;&quot;&quot;</span>
        <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> re.match(<span class="hljs-string">r&apos;^1[345789]\d{9}$&apos;</span>, value):
            <span class="hljs-keyword">raise</span> serializers.ValidationError(<span class="hljs-string">&apos;&#x624B;&#x673A;&#x53F7;&#x683C;&#x5F0F;&#x9519;&#x8BEF;&apos;</span>)
        <span class="hljs-keyword">return</span> value

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">validate_allow</span><span class="hljs-params">(self, value)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;&#x68C0;&#x9A8C;&#x7528;&#x6237;&#x662F;&#x5426;&#x540C;&#x610F;&#x534F;&#x8BAE;&quot;&quot;&quot;</span>
        <span class="hljs-keyword">if</span> value != <span class="hljs-string">&apos;true&apos;</span>:
            <span class="hljs-keyword">raise</span> serializers.ValidationError(<span class="hljs-string">&apos;&#x8BF7;&#x540C;&#x610F;&#x7528;&#x6237;&#x534F;&#x8BAE;&apos;</span>)
        <span class="hljs-keyword">return</span> value

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">validate</span><span class="hljs-params">(self, data)</span>:</span>
        <span class="hljs-comment"># &#x5224;&#x65AD;&#x4E24;&#x6B21;&#x5BC6;&#x7801;</span>
        <span class="hljs-keyword">if</span> data[<span class="hljs-string">&apos;password&apos;</span>] != data[<span class="hljs-string">&apos;password2&apos;</span>]:
            <span class="hljs-keyword">raise</span> serializers.ValidationError(<span class="hljs-string">&apos;&#x4E24;&#x6B21;&#x5BC6;&#x7801;&#x4E0D;&#x4E00;&#x81F4;&apos;</span>)

        <span class="hljs-comment"># &#x5224;&#x65AD;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;</span>
        redis_conn = get_redis_connection(<span class="hljs-string">&apos;verify_codes&apos;</span>)
        mobile = data[<span class="hljs-string">&apos;mobile&apos;</span>]

        real_sms_code = redis_conn.get(<span class="hljs-string">&apos;sms_%s&apos;</span> % mobile)
        <span class="hljs-keyword">if</span> real_sms_code <span class="hljs-keyword">is</span> <span class="hljs-keyword">None</span>:
            <span class="hljs-keyword">raise</span> serializers.ValidationError(<span class="hljs-string">&apos;&#x65E0;&#x6548;&#x7684;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;&apos;</span>)
        <span class="hljs-keyword">if</span> data[<span class="hljs-string">&apos;sms_code&apos;</span>] != real_sms_code.decode():
            <span class="hljs-keyword">raise</span> serializers.ValidationError(<span class="hljs-string">&apos;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;&#x9519;&#x8BEF;&apos;</span>)

        <span class="hljs-keyword">return</span> data

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">create</span><span class="hljs-params">(self, validated_data)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x521B;&#x5EFA;&#x7528;&#x6237;
        &quot;&quot;&quot;</span>
        <span class="hljs-comment"># &#x79FB;&#x9664;&#x6570;&#x636E;&#x5E93;&#x6A21;&#x578B;&#x7C7B;&#x4E2D;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x5C5E;&#x6027;</span>
        <span class="hljs-keyword">del</span> validated_data[<span class="hljs-string">&apos;password2&apos;</span>]
        <span class="hljs-keyword">del</span> validated_data[<span class="hljs-string">&apos;sms_code&apos;</span>]
        <span class="hljs-keyword">del</span> validated_data[<span class="hljs-string">&apos;allow&apos;</span>]
        user = super().create(validated_data)

        <span class="hljs-comment"># &#x8C03;&#x7528;django&#x7684;&#x8BA4;&#x8BC1;&#x7CFB;&#x7EDF;&#x52A0;&#x5BC6;&#x5BC6;&#x7801;</span>
        user.set_password(validated_data[<span class="hljs-string">&apos;password&apos;</span>])
        user.save()

        <span class="hljs-keyword">return</span> user

    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Meta</span>:</span>
        model = User
        fields = (<span class="hljs-string">&apos;id&apos;</span>, <span class="hljs-string">&apos;username&apos;</span>, <span class="hljs-string">&apos;password&apos;</span>, <span class="hljs-string">&apos;password2&apos;</span>, <span class="hljs-string">&apos;sms_code&apos;</span>, <span class="hljs-string">&apos;mobile&apos;</span>, <span class="hljs-string">&apos;allow&apos;</span>)
        extra_kwargs = {
            <span class="hljs-string">&apos;id&apos;</span>: {<span class="hljs-string">&apos;read_only&apos;</span>: <span class="hljs-keyword">True</span>},
            <span class="hljs-string">&apos;username&apos;</span>: {
                <span class="hljs-string">&apos;min_length&apos;</span>: <span class="hljs-number">5</span>,
                <span class="hljs-string">&apos;max_length&apos;</span>: <span class="hljs-number">20</span>,
                <span class="hljs-string">&apos;error_messages&apos;</span>: {
                    <span class="hljs-string">&apos;min_length&apos;</span>: <span class="hljs-string">&apos;&#x4EC5;&#x5141;&#x8BB8;5-20&#x4E2A;&#x5B57;&#x7B26;&#x7684;&#x7528;&#x6237;&#x540D;&apos;</span>,
                    <span class="hljs-string">&apos;max_length&apos;</span>: <span class="hljs-string">&apos;&#x4EC5;&#x5141;&#x8BB8;5-20&#x4E2A;&#x5B57;&#x7B26;&#x7684;&#x7528;&#x6237;&#x540D;&apos;</span>,
                }
            },
            <span class="hljs-string">&apos;password&apos;</span>: {
                <span class="hljs-string">&apos;write_only&apos;</span>: <span class="hljs-keyword">True</span>,
                <span class="hljs-string">&apos;min_length&apos;</span>: <span class="hljs-number">8</span>,
                <span class="hljs-string">&apos;max_length&apos;</span>: <span class="hljs-number">20</span>,
                <span class="hljs-string">&apos;error_messages&apos;</span>: {
                    <span class="hljs-string">&apos;min_length&apos;</span>: <span class="hljs-string">&apos;&#x4EC5;&#x5141;&#x8BB8;8-20&#x4E2A;&#x5B57;&#x7B26;&#x7684;&#x5BC6;&#x7801;&apos;</span>,
                    <span class="hljs-string">&apos;max_length&apos;</span>: <span class="hljs-string">&apos;&#x4EC5;&#x5141;&#x8BB8;8-20&#x4E2A;&#x5B57;&#x7B26;&#x7684;&#x5BC6;&#x7801;&apos;</span>,
                }
            }
</code></pre>
<p>&#x89C6;&#x56FE;</p>
<pre><code class="lang-python"><span class="hljs-comment"># users/views.py</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserView</span><span class="hljs-params">(CreateAPIView)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x7528;&#x6237;&#x6CE8;&#x518C;
    &quot;&quot;&quot;</span>
    serializer_class = serializers.CreateUserSerializer
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../C02-Users/UserModel.html" class="navigation navigation-prev " aria-label="Previous page: 用户模型类"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../C02-Users/CORS.html" class="navigation navigation-next " aria-label="Next page: 跨域CORS"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
